Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate nested ifs (bis) #4

Merged
merged 2 commits into from
Jan 21, 2016

Conversation

plexus
Copy link
Member

@plexus plexus commented Jan 20, 2016

@Robsteranium what do you think of this? I started from your branch (#2) but split the cond code example up, and added an extra example. This way it follows the pattern that you also used for if, introduce, general form, more elaborate example.

Before:

2016-01-20-181102_1040x604_scrot


After:

2016-01-20-181012_1016x582_scrot
2016-01-20-181030_1054x352_scrot
2016-01-20-181036_1054x401_scrot

Robsteranium and others added 2 commits January 20, 2016 14:41
Spells out the situation with nested `if`s to better demonstrate why
`cond` is useful.

Would be better with an example that needs yet more control paths (to
demonstrate scalability of `cond`).
This follows the same pattern used to introduce `if`: start with an
example and explanation, show the general form, then show a more
elaborate example.
@Robsteranium
Copy link
Collaborator

Looks great.

Perhaps we should go a step further and replace the first example with the one you've prepared for the last example (i.e. adding a corresponding nested ifversion)?

@plexus
Copy link
Member Author

plexus commented Jan 20, 2016

Yeah that might be a good idea. We are looking at it now as well, this if example is also what is used to introduce if, but it's not a very good example. Something that's unrelated to the turtle thing would also be better there.

@Robsteranium
Copy link
Collaborator

👍

@jellea
Copy link
Member

jellea commented Jan 21, 2016

Looks good to me!

@plexus
Copy link
Member Author

plexus commented Jan 21, 2016

Hold off on it a little longer, I'm making more changes to the control flow chapter to remove references to the turtle thing

@plexus
Copy link
Member Author

plexus commented Jan 21, 2016

2016-01-21-181638_1045x479_scrot
2016-01-21-181644_1013x607_scrot
2016-01-21-181652_1017x724_scrot
2016-01-21-181701_1045x504_scrot
2016-01-21-181711_1050x736_scrot
2016-01-21-181719_1046x390_scrot
2016-01-21-181725_1040x384_scrot
2016-01-21-181734_1063x813_scrot
2016-01-21-181741_1097x704_scrot

@Robsteranium
Copy link
Collaborator

What about starting with: (ordinal 1) and (ordinal 2), then progressing to 3+ rather than skipping 2nd/3rd?

@plexus
Copy link
Member Author

plexus commented Jan 21, 2016

I thought it made more sense this way because "th" is the general case (the :else case).

@Robsteranium
Copy link
Collaborator

Yeah I know what you mean.

At that point though, they've not seen :else so they will still be thinking in pair-wise splits (i.e. not specifics vs general). It just seemed more natural to me to handle them in order.

I don't suppose it'll make much difference either way.

@plexus
Copy link
Member Author

plexus commented Jan 21, 2016

Yeah I can see your point as well, it might help to drive home the point that the "else" branch is not equivalent to the "if" branch though, since it's really more of a catch-all/fallback.

Many people won't be familiar with the word "ordinal". It's introduced straight away with some examples so it should be reasonably clear from context, and the coach can clarify. Would that be good enough, or should we add an extra paragraph to introduce the "ordinal" concept?

The second version of ordinal is actually still not 100% correct, e.g. 21st, 102nd. Maybe best to remain silent about that, or do we add that generalisation as a bonus exercise as well?

@Robsteranium
Copy link
Collaborator

I think ordinal is easy enough to explain - you might add a "Details" link though. It's not as mathsy as modulo etc.

Dealing with 102nd etc is a good exercise but that will require people to use modulo! At least that's how I'd solve it..?

@plexus
Copy link
Member Author

plexus commented Jan 21, 2016

You would need modulo, yeah, and an exception for 11th, 12th, 13th. This how Ruby on Rails implements it

def ordinal(number)
  abs_number = number.to_i.abs

  if (11..13).include?(abs_number % 100)
    "th"
  else
    case abs_number % 10
      when 1; "st"
      when 2; "nd"
      when 3; "rd"
      else    "th"
    end
  end
end

I would rather not point that out though, I don't think people should go that deep on this one exercise.

@Robsteranium
Copy link
Collaborator

Ah yeah. Good point. Maybe that's better swept under the carpet for now!

plexus added a commit that referenced this pull request Jan 21, 2016
@plexus plexus merged commit 4d77a03 into clojurebridge-berlin:gh-pages Jan 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants